// Create "namespaces"
Game = new Object();

//  Loads all needed modules. Eliminates including all scripts into HTML header
require("x-res/js/core/net/Xml.js");
require("x-res/js/core/net/Html.js");
require("x-res/js/core/net/Request.js");
require("x-res/js/core/net/Net.js");
require("x-res/js/core/lang/Events.js");

function require(url)
{
    var loadedBefore = false;
    if (typeof(__loadedList) != "undefined")
    {
        loadedBefore = arrContainsKey(__loadedList, url);
    }

    if (document.createElement && document.getElementsByTagName && !loadedBefore)
    {
        var s = document.createElement('script');
        var h = document.getElementsByTagName('head');
        if (s && h.length)
        {
//            url = url.toLowerCase();
            s.src = url;
            h[0].appendChild(s);
            if (typeof(__loadedList) == "undefined")
            {
                __loadedList = new Array();
            }
            __loadedList.push(url);
        }
    }
}

function namespace(ns)
{
    if (typeof(__namespaces) == "undefined")
    {
        __namespaces = new Array();
    }

    var names = ns.split('.');
    var name = "";
    for(var i = 0; i < names.length; i++)
    {
        name += name ? "." + names[i] : names[i];
        if (eval("typeof(" + name + ")") == "undefined" && !arrContainsValue(__namespaces, name))
        {
            __namespaces.push(name);
            var s = name + " = new Object();";
            eval(s);
        }
    }
}
